package com.dlc.shop.systemtest.data.amount;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.UUID;
import com.dlc.shop.bean.app.dto.DvyTypeDTO;
import com.dlc.shop.bean.app.dto.OrderSelfStationDto;
import com.dlc.shop.bean.app.param.OrderFlowLogParam;
import com.dlc.shop.bean.app.param.OrderItemParam;
import com.dlc.shop.bean.app.param.OrderShopParam;
import com.dlc.shop.bean.app.vo.ProductVO;
import com.dlc.shop.bean.model.Product;
import com.dlc.shop.bean.model.Sku;
import com.dlc.shop.groupbuy.common.api.dto.ApiGroupSkuDto;
import com.dlc.shop.groupbuy.common.api.param.ApiGroupOrderSubmitParam;
import com.dlc.shop.groupbuy.common.api.param.GroupOrderParam;
import com.dlc.shop.groupbuy.common.enums.GroupActivityStatusEnum;
import com.dlc.shop.groupbuy.common.model.GroupActivity;
import com.dlc.shop.systemtest.api.amount.ProductApi;
import com.dlc.shop.systemtest.api.amount.SkuApi;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author lanhai
 * 团购测试数据
 */
public class GroupData {
    public static GroupActivity getGroupActivity(Long prodId){
        GroupActivity groupActivity = new GroupActivity();
        groupActivity.setActivityName("团购测试");
        groupActivity.setStartTime(DateUtil.parse("2021-1-1 00:00:00","yyyy-MM-dd HH:mm:ss"));
        groupActivity.setEndTime(DateUtil.parse("2025-1-1 00:00:00","yyyy-MM-dd HH:mm:ss"));
        groupActivity.setGroupValidTime(15);
        groupActivity.setHasRobot(0);
        groupActivity.setPrice(10.00);
        groupActivity.setProdId(prodId);
        groupActivity.setGroupNumber(2);
        groupActivity.setHasMaxNum(0);
        groupActivity.setHasGroupTip(1L);
        List<Sku> skuList = SkuApi.getAllSkuList(prodId);
        List<ApiGroupSkuDto> skuDtos = skuList.stream().map(i -> BeanUtil.copyProperties(i, ApiGroupSkuDto.class)).collect(Collectors.toList());
        skuDtos.forEach(i->i.setActPrice(10.00));
        groupActivity.setGroupSkuList(skuDtos);
        Product productInfo = ProductApi.getProductInfo(prodId);
        groupActivity.setProdName(productInfo.getProdName());
        groupActivity.setProdPic(productInfo.getPic());
        groupActivity.setStatus(GroupActivityStatusEnum.ENABLE.value());
        groupActivity.setActivityStatus(null);
        groupActivity.setIsPreheat(0);
        return groupActivity;
    }

    public static GroupOrderParam getGroupOrderParam(Long productId, Long groupTeamId, Integer prodCount) {
        ProductVO product = ProductApi.getProdInfo(productId);
        GroupOrderParam groupOrderParam = new GroupOrderParam();
        groupOrderParam.setAddrId(0L);
        groupOrderParam.setGroupSkuId(product.getGroupActivityVO().getGroupSkuList().get(0).getGroupSkuId());
        groupOrderParam.setGroupTeamId(Objects.isNull(groupTeamId) ? 0L : groupTeamId);
        groupOrderParam.setIsScorePay(0);
        groupOrderParam.setUserChangeCoupon(0);
        groupOrderParam.setUserUseScore(0L);



        List<DvyTypeDTO> dvyTypes = new ArrayList<>();
        DvyTypeDTO dvyTypeDTO = new DvyTypeDTO();
        dvyTypeDTO.setDvyType(1);
        dvyTypeDTO.setShopId(product.getShopId());
        dvyTypes.add(dvyTypeDTO);

        groupOrderParam.setDvyTypes(dvyTypes);

        OrderItemParam orderItemParam = new OrderItemParam();
        orderItemParam.setDistributionCardNo("");
        orderItemParam.setProdCount(prodCount);
        orderItemParam.setProdId(productId);
        orderItemParam.setShopId(product.getShopId());
        orderItemParam.setSkuId(product.getSkuList().get(0).getSkuId());

        groupOrderParam.setOrderItem(orderItemParam);

        return groupOrderParam;
    }

    public static ApiGroupOrderSubmitParam getApiGroupOrderSubmitParam(Long groupTeamId, Long shopId){
        ApiGroupOrderSubmitParam apiGroupOrderSubmitParam = new ApiGroupOrderSubmitParam();
        apiGroupOrderSubmitParam.setGroupTeamId(groupTeamId);
        apiGroupOrderSubmitParam.setVirtualRemarkList(null);
        apiGroupOrderSubmitParam.setOrderInvoiceList(null);

        OrderSelfStationDto orderSelfStationDto = new OrderSelfStationDto();
        orderSelfStationDto.setStationTime("");
        orderSelfStationDto.setStationUserMobile("");
        orderSelfStationDto.setStationUserName("");

        apiGroupOrderSubmitParam.setOrderSelfStationDto(orderSelfStationDto);

        List<OrderShopParam> orderShopParams = new ArrayList<>();
        OrderShopParam orderShopParam = new OrderShopParam();
        orderShopParam.setRemarks("");
        orderShopParam.setShopId(shopId);
        orderShopParams.add(orderShopParam);


        OrderFlowLogParam orderFlowLogParam = new OrderFlowLogParam();
        orderFlowLogParam.setStep(13);
        orderFlowLogParam.setSystemType(2);
        orderFlowLogParam.setVisitType(1);
        orderFlowLogParam.setUuid(UUID.fastUUID().toString());
        orderFlowLogParam.setUuidSession(UUID.fastUUID().toString());

        apiGroupOrderSubmitParam.setOrderFlowLogParam(orderFlowLogParam);
        apiGroupOrderSubmitParam.setOrderShopParams(orderShopParams);

        return apiGroupOrderSubmitParam;
    }

}
